@layout("/common/_container.html"){
<style>
    .BMapLabel{max-width:500px}
</style>
<div class="row" style="width:100%;height:100%">
   <div id="allmap" style="width:100%;height:100%"></div>
</div>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=3.0&ak=u45nFCgs5dNCnKaUPqgiqZqtn3kyq0yR"></script>
<script>
    $(function(){
        var url="/shopInfo/list/"
        $.ajax({
            url:url,
            type:"get",
            processData:false,
            contentType:false,
            dataType: 'json',
            success:function(data){
              console.log(data)
                // -------------百度地图开始-----------------
                // 百度地图API功能
                var map = new BMap.Map("allmap");
                var point = new BMap.Point(117.2,39.12);
                map.centerAndZoom(point, 15);
                map.disableDoubleClickZoom(true);
                map.enableScrollWheelZoom();
                // 编写自定义函数,创建标注
                function addMarker(point,label){
                    var marker = new BMap.Marker(point);
                    map.addOverlay(marker);
                    marker.setLabel(label);
                    marker.addEventListener("click",attribute);
                }
                // 向地图添加店铺个标注
                for(var i=0;i<data.length;i++){
                    var point = new BMap.Point(data[i].lng, data[i].lat);
                    var label = new BMap.Label(data[i].shopName,{offset:new BMap.Size(20,-10)});
                    addMarker(point,label);
                }
                // var bounds = map.getBounds();
                // var sw = bounds.getSouthWest();
                // var ne = bounds.getNorthEast();
                // var lngSpan = Math.abs(sw.lng - ne.lng);
                // var latSpan = Math.abs(ne.lat - sw.lat);
                // for (var i = 0; i < 10; i++) {
                //     var point = new BMap.Point(sw.lng + lngSpan * (Math.random() * 0.7), ne.lat - latSpan * (Math.random() * 0.7));
                //     var label = new BMap.Label("我是id="+i,{offset:new BMap.Size(20,-10)});
                //     addMarker(point,label);
                // }
                // 删除坐标点
                // function deletePoint(){
                //     var allOverlay = map.getOverlays();
                //     for (var i = 0; i < allOverlay.length -1; i++){
                //         if(allOverlay[i].getLabel().content == "我是id=2"){
                //             map.removeOverlay(allOverlay[i]);
                //             return false;
                //         }
                //     }
                // }
                function attribute(e){
                    var p = e.target;
                    alert("marker的位置是" + p.getPosition().lng + "," + p.getPosition().lat);
                }
                // -------------百度地图结束-----------------
            },
            error:function(e){
                console.log(e)
                swal({
                    title: "提示",
                    text: "服务器异常",
                    type: "success"
                });
            }
        });
    })


</script>
@}
